/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

FIVe3D
Flash Interactive Vector-based 3D
Mathieu Badimon  |  five3d@mathieu-badimon.com

http://five3D.mathieu-badimon.com  |  http://five3d.mathieu-badimon.com/archives/  |  http://code.google.com/p/five3d/

/*///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

import net.badimon.five3D.display.DisplayObject;
import net.badimon.five3D.display.DisplayObjectContainer;
import net.badimon.five3D.display.Motif;
import net.badimon.five3D.display.Scene;
import net.badimon.five3D.geom.Angle;

class net.badimon.five3D.display.Shape extends DisplayObject {

	private var __motif:Array;
	private var __renderedmotif:Array;

	function Shape(scene:Scene, parentclip:MovieClip, name:String, depth:Number, parent:DisplayObjectContainer) {
		super(scene, parentclip, name, depth, parent);
		__motif = [];
	}

	public function addMotif(motif:Array):Void {
		__motif = __motif.concat(motif);
		__scene.__render = true;
		__render = true;
	}

	public function render(Void):Void {
		if (!__visible && _clip._visible) _clip._visible = false;
		else if (__visible) {
			if (!_clip._visible) _clip._visible = true;
			if (__render) {
				getMatrices();
				_clip.clear();
				__renderedmotif = Motif.clone(__motif);
				Motif.project(__renderedmotif, __concatenatedmatrix, __scene._viewdistance);
				Motif.draw(_clip, __renderedmotif);
				__render = false;
			}
		}
	}

	private function getMatrices(Void):Void {
		__matrix.createBox(__scalex / 100, __scaley / 100, __scalez / 100, Angle.degreesToRadians(__rotationx), Angle.degreesToRadians(__rotationy), Angle.degreesToRadians(__rotationz), __x, __y, __z);
		__concatenatedmatrix = _parent.__concatenatedmatrix.clone();
		__concatenatedmatrix.concat(__matrix);
	}
}